<?php
/**
 * Created by PhpStorm.
 * User: Woo
 * Date: 2017/12/13
 * Time: 13:57
 */

namespace App\Http\Controllers;


use App\Events\TestEvent;
use App\Helper\ErrorCode;
use App\Jobs\SendMail;
use App\Models\Novel;
use App\Models\ReadHistory;
use App\Models\User;
use ElfSundae\BearyChat\Laravel\BearyChat;
use Illuminate\Http\Request;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Monolog\Handler\ElasticSearchHandler;

class TestController extends Controller
{
    public function index(Request $request){

//        echo $a;
//        event(new TestEvent(123));
//        $res = User::where('id', '>', 0)->max('id');
//        var_dump($res);
//        echo preg_replace('/\{(\w+?)\?\}/', '{$1}', 'hee/baid/{kkk}/{jj?}/{fff?}');
//        $novel = Novel::with(['chapter'=>function($query){
//                        $query->select('novel_id','chapter_name', 'abstract')->where('id', '>', 5);
//                    }])
//                    ->where('id', '<', 10)
//                    ->limit(2)
//                    ->get();
//        $novel = Novel::limit(2)->get();
//        $novel->each(function($item){
//            return $item['chapter'] = $item->chapter()->limit(5)->get();
//        });
//        return $novel;
//        ElasticSearchHandler::class;
//        User::create();
        dispatch(new SendMail(123,456));
    }













    /************************************************************
     ************************************************************/
    public function bearyChat(){
        $str = exec('cd /home/wwwroot/api && git log -1 --pretty=format:"%s"');
        var_dump($str);
        BearyChat::client('dushuba')->send($str);
    }
    public function redis(){
        $keys = Redis::keys('*');
        $res = [];
        foreach ($keys as $key){
            $res[] = [
                'key'=>$key,
                'ttl'=>Redis::ttl($key),
            ];
        }
        print_r($res);
    }

}